<template>
  <el-container>
  <el-header>
    <div class="left">
      <!-- <img src="../assets/imgs/shop.png"> -->
      <span>教育医疗优智多</span>
    </div>
    <div class="right">
      <span>欢迎您: {{ userInfo.username }}</span>
      <el-button type="danger" size="mini" @click="logout">退出</el-button>
    </div>
  </el-header>
  <el-container>
    <el-aside width="auto">
      <div class="toggle-button" @click="isCollapse=!isCollapse">
        |||
      </div>
       <el-menu
      :default-active="$route.path"
      unique-opened router
      :collapse=isCollapse
      :collapse-transition="false">
      <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
        <template slot="title">
          <i :class="iconObj[item.icon]"></i>
          <span>{{item.authName}}</span>
        </template>
        <el-menu-item :index="subItem.url" v-for="subItem in item.children" :key="subItem.id">
          <i class="el-icon-menu"></i>
          {{subItem.authName}}
        </el-menu-item>
      </el-submenu>
    </el-menu>
    </el-aside>
    <el-main><router-view></router-view></el-main>
  </el-container>
</el-container>
</template>

<script>
export default {
  data() {
    return {
      userInfo:null,
      menuList:[],
      isCollapse:false,
      iconObj:{
        201: "iconfont icon-shouye",
        125: "iconfont icon-users",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        104: "iconfont icon-tijikongjian",
        105: "iconfont icon-baobiao"
      }
    }
  },
  created() {
    this.userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
    // this.menuList = this.userInfo.menu_dict
    // console.log('menuList', this.menuList)
    this.getMenuList()
  },
  methods: {
    logout(){
      sessionStorage.removeItem('userInfo')
      this.$router.push('/login')
    },
    async getMenuList(){
      const {data:res} = await this.$http.get('/menus/')
      console.log('menus xxx', res)
      // if(res.meta.status === 200){
      //   return this.$message.error(res.meta.msg);
      // }
      this.menuList = res.data
      // console.log('menuList', this.menuList)
    }
  },
}
</script>
<style lang="less" scoped>
  .el-container{
    height: 100%;
  }
  .el-header{
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 50px!important;
    background: url('../assets/imgs/header_bg.gif') repeat-x center;
    color: white;
    .left{
        display: flex;
        align-items: center;
      img{
        width: 40px;
        margin-right: 20px;
      }
      span{
        font-size: 20px;
      }
    }
    .right{
      span{
          margin-right: 20px;
        }
  }
  }
  .el-aside{
    .toggle-button{
      background-color: #60779d;
      color: white;
      font-size: 10px;
      line-height: 24px;
      text-align: center;
      letter-spacing: 0.2rem;
      cursor: pointer;
    }
    .el-menu{
      border-right: 0;
      .iconfont{
        margin-right: 10px;
      }
    }
  }
  .el-main{
    // background-color: #eaedf1;
    background-color: #F5F5F5;
  }
</style>